package sysu.el.array.ints.functors;

public abstract class Fun2Int {
	public abstract int apply(int p1, int p2);
	static public Fun2Int plus = new Fun2Int(){
		@Override
		public int apply(int p1, int p2) {
			return p1 + p2;
		}
	};
	
	static public Fun2Int minus = new Fun2Int(){
		@Override
		public int apply(int p1, int p2) {
			return p1 - p2;
		}
	};
	
	static public Fun2Int multiply = new Fun2Int(){
		@Override
		public int apply(int p1, int p2) {
			return p1 * p2;
		}
	};
	
	static public Fun2Int divide = new Fun2Int(){
		@Override
		public int apply(int p1, int p2) {
			return p1 / p2;
		}
	};
	
	static public Fun2Int min = new Fun2Int(){
		public int apply(int p1, int p2) {
			// TODO Auto-generated method stub
			if (p1 <= p2)
				return p1;
			else return p2;
		}
	};
	
	static public Fun2Int max = new Fun2Int(){
		public int apply(int p1, int p2) {
			// TODO Auto-generated method stub
			if (p1 >= p2)
				return p1;
			else return p2;
		}

	};
	
	
	static private Fun2IntParamArr2 Fun2IntParamArr2 = new Fun2IntParamArr2(null){
		@Override
		public int apply(int p1, int p2) {
			// TODO Auto-generated method stub
			return arr[p1][p2];
		}
	};
	
	static public Fun2Int getFun2IntParamArr2(int arr[][]){
		Fun2IntParamArr2.arr = arr;
		return Fun2IntParamArr2;
	}
	
	static public Fun2Int buildPlusContent(int arr[]){
		Fun2Int fun = new Fun2IntParamArr(arr) {
			@Override
			public int apply(int p1, int p2) {
				// TODO Auto-generated method stub
				return arr[p1] + arr[p2];
			}
		};
		return fun;
	}
	
//	static Fun2IntParamArr2_sum plusContentArr2 = new Fun2IntParamArr2_sum(null); 
//	static public Fun2Int getPlusContent(int arr[][]){
//		plusContentArr2.reset(arr);
//		return plusContentArr2;
//	}
//	static public Fun2Int buildPlusContent(int arr[][]){
//		Fun2Int fun = new Fun2IntParamArr2_sum(arr);
//		return fun;
//	}
}

abstract class Fun2IntParamArr extends Fun2Int{
	public int arr[];
	public Fun2IntParamArr(int arr0[]){
		arr = arr0;
	}
}

abstract class Fun2IntParamArr2 extends Fun2Int{
	public int arr[][];
	public Fun2IntParamArr2(int arr0[][]){
		arr = arr0;
	}
}

class Fun2IntParamArr2_sum extends Fun2IntParamArr2{
	int sum;
	public Fun2IntParamArr2_sum(int [][] arr){
		super(arr);
		sum = 0;
	}
	
	public void reset(int [][] arr){
		this.arr = arr;
		this.sum = 0;
	}
	
	@Override
	public int apply(int p1, int p2) {
		// TODO Auto-generated method stub
		sum += arr[p1][p2];
		return sum;
	}
}